package cc.lj.internal.coupons.interfaces.facade;

import cc.lj.internal.api.coupons.dto.TicketBatchApiDTO;
import cc.lj.internal.core.exception.SysExceptionEnum;
import cc.lj.internal.core.http.HttpResult;
import cc.lj.internal.core.model.PageBean;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.application.service.CapBatchAppService;
import cc.lj.internal.coupons.application.service.TicketBatchAppService;
import cc.lj.internal.coupons.domain.ticket.model.vo.TicketBatchDO;
import cc.lj.internal.coupons.domain.ticket.service.ITicketBatchDomainService;
import cc.lj.internal.coupons.interfaces.dto.CapBatchDTO;
import cc.lj.internal.coupons.interfaces.dto.TicketBatchDTO;
import cc.lj.internal.coupons.interfaces.dto.command.InsertCapBatchCommand;
import cc.lj.internal.coupons.interfaces.dto.command.UpdateCapBatchCommand;
import cc.lj.internal.coupons.interfaces.dto.convert.TicketBatchDTOConvertDO;
import cc.lj.internal.coupons.interfaces.dto.query.CapBatchQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.List;

/**
 * 电子券批次表接口
 * @author liangxifeng
 * @date 2021-12-20
 */
@RestController
@Slf4j
@Validated
@Api(tags = "电子券批次表接口")
@RequestMapping("ticketBatch")
public class TicketBatchController {
    @Resource(name = "ticketBatchAppService")
    private TicketBatchAppService batchAppService;

    @Resource(name = "ticketBatchDomainServiceImpl")
    private ITicketBatchDomainService batchDomainService;
    /**
     * 查询所有未开始,且为绑定过促销活动的电子券批次
     */
    @PostMapping("/getValidList")
    @ApiOperation(value = "查询所有未开始且未绑定过活动的电子券批次",notes = "错误码：无")
    public HttpResult<List<TicketBatchDTO>> getValidList() {
        List<TicketBatchDTO> ticketBatchDTOList = batchAppService.getNoStartList();
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),ticketBatchDTOList);
    }

    /**
     * 通过主键批量查询电子券批次数据
     * @param batchIds 电子券批次表主键List
     * @return 电子批次list
     */
    @PostMapping("/getListByIds")
    @ApiOperation(value = "通过主键批量查询电子券批次数据",notes = "错误码：无")
    public HttpResult<List<TicketBatchApiDTO>> getListByIds(@RequestBody List<Integer> batchIds) {
        List<TicketBatchDO> list = batchDomainService.getListByIds(batchIds);
        List<TicketBatchApiDTO> listDTO = new ArrayList<>();
        for (TicketBatchDO ticketBatchDO : list) {
            listDTO.add(TicketBatchDTOConvertDO.INSTANCE.convertToApiDTO(ticketBatchDO));
        }
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),listDTO);
    }

    /**
     * 查询在有效期内的电子券批次列表（只查连续有效期类型的）
     * @return
     * @author zhaoyong
     */
    @GetMapping("/getValidBatchList")
    public List<TicketBatchDTO> getValidBatchList()
    {
        List<TicketBatchDTO> list = batchAppService.getValidList();
        return list;
    }

    /**
     * 通过主键查询券批次信息
     * @param id
     * @return
     * @author zhaoyong
     */
    @GetMapping("/getById")
    public TicketBatchDTO getById(@Min(1) @RequestParam Integer id)
    {
        TicketBatchDO byId = batchDomainService.getById(id);
        return TicketBatchDTOConvertDO.INSTANCE.convert(byId);
    }

}
